package cn.chint.manage.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate4.HibernateCallback;
import org.springframework.orm.hibernate4.HibernateTemplate;
import org.springframework.stereotype.Repository;

import cn.chint.po.SysUser;

@Repository
public class AdminDaoImpl implements cn.chint.manage.dao.AdminDao {
	@Autowired
	HibernateTemplate hibernateTemplate;

	@SuppressWarnings({"unchecked", "rawtypes"})
	public SysUser findChannelUser(final String username, final String password) {
		List<SysUser> ls = (List<SysUser>) this.hibernateTemplate.execute(new HibernateCallback() {
			@Override
			public Object doInHibernate(Session session) throws HibernateException {
				return session.createQuery("from SysUser u where u.username=:username and u.password=:password")
						.setString("username", username).setString("password", password).list();

			}
		});

		if (ls.size() > 0) {
			SysUser sysUser = ls.get(0);
			return sysUser;
		} else {
			return null;
		}

	}
}
















